package com.sm.controller;

import com.sm.domain.dto.Result;
import com.sm.domain.po.Permission;
import com.sm.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {

	@Autowired
	private PermissionService permissionService;

	@GetMapping("/bindDefaultRole/{userId}")
	public Result bindDefaultRole(@PathVariable("userId") Long userId) {
		permissionService.bindDefaultRole(userId);
		return Result.ok();
	}

	@GetMapping("/getUserRoleCode/{userId}")
	public Permission getUserRoleCode(@PathVariable("userId") Long userId) {
		return permissionService.getUserRoleCode(userId);
	}

	@GetMapping("/upgradeToAdmin/{userId}")
	public Result upgradeToAdmin(@PathVariable("userId") Long userId) {
		return permissionService.upgradeToAdmin(userId);
	}

	@GetMapping("/downgradeToUser/{userId}")
	public Result downgradeToUser(@PathVariable("userId") Long userId) {
		return permissionService.downgradeToUser(userId);
	}

	@GetMapping("/getUserRoleIds")
	public List<Long> getUserRoleIds() {
		return permissionService.getUserRoleIds();
	}
}
